/**
 * 注册相关API接口
 */
import { request } from '@/utils/request'
import type { CustomAxiosRequestConfig } from '@/utils/request'
import type { RegisterParams, RegisterResponse, RegisterUserData } from '@/types/register'
import type { ApiResponse } from '@/types/api'

/**
 * 用户注册
 * @param data 注册参数
 * @returns 注册响应
 */
export async function register(data: RegisterParams): Promise<RegisterResponse> {
  const response = await request.post<ApiResponse<RegisterUserData>>('/auth/register', data, {
    showLoading: true,
    loadingText: '注册中...',
    showSuccess: true,
    successMessage: '注册成功'
  } as CustomAxiosRequestConfig)
  return response.data
}

/**
 * 检查用户名是否可用
 * @param username 用户名
 * @returns 检查结果
 */
export async function checkUsername(username: string): Promise<{ available: boolean }> {
  const response = await request.get(`/auth/check-username?username=${username}`)
  return response.data.data
}

/**
 * 检查邮箱是否可用
 * @param email 邮箱
 * @returns 检查结果
 */
export async function checkEmail(email: string): Promise<{ available: boolean }> {
  const response = await request.get(`/auth/check-email?email=${email}`)
  return response.data.data
}